from utils import conn, c


def create_db():
    # 建表
    sql = "CREATE TABLE RAW_PRICE_DATAS(raw_price_id VARCHAR2(100) CONSTRAINT raw_price_id PRIMARY KEY NOT NULL, price_date Date, avg_price VARCHAR2(100), lower_price VARCHAR2(100), higher_price VARCHAR2(100), unit VARCHAR2(100), raw_name VARCHAR2(100), raw_type VARCHAR2(100), change_amount VARCHAR2(100), change_range VARCHAR2(100), create_time Date, source VARCHAR2(100), reserve1 VARCHAR2(100), reserve2 VARCHAR2(100))"
    c.execute(sql)
    conn.commit()


def insert_db(db_dict):
    sql = "INSERT INTO RAW_PRICE_DATAS(raw_price_id, avg_price, lower_price, higher_price, unit, change_amount, change_range, price_date, raw_name, raw_type, create_time, source) VALUES('{}', '{}', '{}', '{}', '{}', '{}', '{}', to_date('{}','yyyy/MM/dd'), '{}', '{}', to_date('{}','yyyy/MM/dd HH24:mi:ss'),'{}')".format(db_dict["id"], db_dict["avg_price"], db_dict["lower_price"], db_dict["higher_price"], db_dict["unit"], db_dict["change_amount"], db_dict["change_range"], db_dict["price_date"], db_dict["raw_name"], db_dict["raw_type"], db_dict["create_time"], db_dict["source"])
    c.execute(sql)
    conn.commit()
